package cn.xunjie.ymcc.service.impl;

import cn.xunjie.ymcc.service.ITokenService;
import cn.xunjie.ymcc.util.StrUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;
@Service
public class TokenServiceImpl implements ITokenService {
    @Autowired
    private RedisTemplate<Object,Object> redisTemplate;
    @Override
    public String createToken(String courseId) {
        Long loginId = 1L;
        String token = StrUtils.getComplexRandomString(8);
        String key = courseId+":"+loginId;
        redisTemplate.opsForValue().set(key,token,10, TimeUnit.MINUTES);
        return token;
    }
}
